# -*- coding:utf-8 -*-
# @time    : 2021/9/5 6:02
# @Author  : zhang jin xia
# @Filename: PyCharm
import os

from appium import webdriver
from app_po_project.app_project.page.base_page import BasePage
from app_po_project.app_project.page.main_page import MainPage


class App(BasePage):

    def start(self):
        if self.driver==None:
            desired_caps = {
                "platformName": "android",  # 使用的平台
                "deviceName": "127.0.0.1:7555",  # 连接的服务
                "appPackage": "com.tencent.wework",  # 连接的应用
                "appActivity": "com.tencent.wework.launch.WwMainActivity",  # 应用的页面
                "noRest": True,  # 记录弹窗，第二次不打开
                "dontStopAppOnResrt": True,  # 首次启动的时候不停止app
                "skipDeviceInitialization": True,  # 跳过安装，权限设置等操作
                "skipServerInstallation": True,
            }
            # 链接客户端
            self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
            # 全局隐式等待
            self.driver.implicitly_wait(60)
        else:
            # launch_app启动页面
            self.driver.launch_app()
        return self

    def stop(self):
        self.driver.quit()

    def goto_main(self):
        """
        入口,点击通讯录
        :return:s
        """
        return MainPage(self.driver)


